package com.newdjk.newdoctor.utils;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
import android.util.Log;

import androidx.core.app.NotificationCompat;

import com.newdjk.newdoctor.MyApplication;
import com.newdjk.newdoctor.R;
import com.newdjk.newdoctor.receiver.NotificationClickReceiver;
import com.newdjk.newdoctor.ui.SplashActivity;

public class NotificationUtils {
    private static final String TAG = "PushMessageReceiver";
    private static int ChannelId=100;

    private static final String PRIMARY_CHANNEL = "my_jpush";

    public static void showNotification(Context context, String content, String title) {

//        NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
//
//        NotificationCompat.Builder builder;
//        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//适配8.0,自行查看8.0的通知，主要是NotificationChannel
//            NotificationChannel chan1 = new NotificationChannel(PRIMARY_CHANNEL,
//                    "Primary Channel", NotificationManager.IMPORTANCE_DEFAULT);
//            chan1.setLightColor(Color.GREEN);
//            chan1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
//            notificationManager.createNotificationChannel(chan1);
//            builder = new NotificationCompat.Builder(context, PRIMARY_CHANNEL);
//        } else {
//            builder = new NotificationCompat.Builder(context, null);
//        }
//        builder.setContentText(content)//notification的一些设置，具体的可以去官网查看
//                .setContentTitle(title) //设置通知标题
//                .setPriority(Notification.PRIORITY_DEFAULT)
//                .setDefaults(Notification.DEFAULT_VIBRATE)
//                .setOnlyAlertOnce(true)
//                .setWhen(System.currentTimeMillis())
//                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon))
//                .setSmallIcon(R.mipmap.icon);
//        Intent intent = new Intent(context, NotificationClickReceiver.class);
//        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
//        builder.setContentIntent(pendingIntent);
//        Notification mNotification = builder.build();
//        notificationManager.notify(ChannelId++, mNotification);




        //获取状态通知栏管理
        NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder builder;
        //判断是否是8.0Android.O
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel chan1 = new NotificationChannel("static",
                    "Primary Channel", NotificationManager.IMPORTANCE_HIGH);
            manager.createNotificationChannel(chan1);
            builder = new NotificationCompat.Builder(context, "static");
        } else {
            builder = new NotificationCompat.Builder(context);
        }
        //对builder进行配置
        builder.setContentTitle(title) //设置通知栏标题
                .setContentText(content) //设置通知栏显示内容
                .setPriority(NotificationCompat.PRIORITY_MAX) //设置通知优先级
                .setSmallIcon(R.mipmap.icon)
                .setPriority(Notification.PRIORITY_DEFAULT)
               .setDefaults(Notification.DEFAULT_VIBRATE)
                .setAutoCancel(true); //设置这个标志当用户单击面板就可以将通知取消
        //绑定intent，点击图标能够进入某activity
        Intent mIntent=new Intent(context, SplashActivity.class);
        PendingIntent mPendingIntent=PendingIntent.getActivity(context, 0, mIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(mPendingIntent);
        //绑定Notification，发送通知请求
    //   manager.notify(ChannelId, builder.build());


        Log.d(TAG, "弹出通知");


    }
}
